clear all


use "$root\data\use.dta", replace


**# Omitted variables with drought and wetness
*First get results with wetness constrols from the main result and ones with omitted variables

foreach crop in corn soybeans {
	local c_name = strproper("`crop'")

	preserve
	local c = cond("`crop'" == "corn", "c", "s")
	rename `c'_d*_* d*_*
	rename `c'_tot_* tot_*
	rename `c'_pdsi_w_* pdsi_w_*
	rename `c'_pmdi_w_* pmdi_w_*
	rename `c'_tbin*_* tbin*_*
	rename `c'_prec_* prec_*
	rename `crop'_production00 production00


**## Yield
	reghdfe ln`crop'_yield d*_b d*_p d*_g pdsi_w_b tbin*b pdsi_w_p tbin*p pdsi_w_g tbin*g if irrigated_ratio<0.1 & N_year_`crop'>10 & lng>-100, absorb(fips i.state#c.year i.state#c.year2 i.year) vce(cluster fips stateyear)
	estimate store `crop'_yield_wet
	
	reghdfe ln`crop'_yield d*_g pdsi_w_g tbin*g if irrigated_ratio<0.1 & N_year_`crop'>10 & lng>-100, absorb(fips i.state#c.year i.state#c.year2 i.year) vce(cluster fips stateyear)
	estimate store `crop'_yield_omit

restore
}


**Results with misspecification: using whole year drought
foreach crop in corn soybeans {
	local c_name = strproper("`crop'")

	preserve
	local c = cond("`crop'" == "corn", "c", "s")
	rename `c'_d*_* d*_*
	rename `c'_tot_* tot_*
	rename `c'_pdsi_w_* pdsi_w_*
	rename `c'_pmdi_w_* pmdi_w_*
	rename `c'_tbin*_* tbin*_*
	rename `c'_prec_* prec_*
	rename `crop'_production00 production00
	
	forvalues s = 0/3 {
		replace d`s'_g = (d`s'_b_w + d`s'_p_w + d`s'_g_w)*7/365 
	}

	reghdfe ln`crop'_yield d*_g pdsi_w_g tbin*g if irrigated_ratio<0.1 & N_year_`crop'>10 & lng>-100, absorb(fips i.state#c.year i.state#c.year2 i.year) vce(cluster fips stateyear)
	estimate store `crop'_yield_mis
	
	
	restore
}


	coefplot  /// 
		(corn_yield_omit, label(Growing Season Only) offset(-0.1) ciopts(color(black) )  msymbol(T)) ///
		(corn_yield_wet, label(All Seasons Separately) offset(0) ciopts(color(black)) msymbol(S)) ///
		(corn_yield_mis, label(Whole Year) offset(0.1) ciopts(color(black) )), bylabel(Corn) || /// 
		(soybeans_yield_omit, label(Growing Season Only) offset(-0.1) ciopts(color(black) ) msymbol(T)) /// 
		(soybeans_yield_wet, label(All Seasons Separately) offset(0) ciopts(color(black)) msymbol(S)) ///
		(soybeans_yield_mis, label(Whole Year) offset(0.1) ciopts(color(black) )), bylabel(Soybeans) ||, ///
		mcolor(black) mfcolor(white) vertical keep(d0_g d1_g d2_g d3_g) yline(0, lcolor(gray) lwidth(0.2)) /// 
		byopts(compact cols(1) graphregion(fcolor(white))) subtitle(, fcolor(white) bmargin(top) bcolor(white)) ///
		groups(d*_g = "Drought Severity") ytitle("ln(yield)") ylab(,labs(small)) xlabel(1 "D0" 2 "D1" 3 "D2" 4 "D3") ///
		legend(rows(1))
	
graph export "$root/results_replication/appendix_figures/a2_omitted_yield.png", as(png) name("Graph") width(3200) height(2400) replace


